
print("Asd")

if not fs.exists('/disk/next_chunk') then
	next_chunk = 1
else
	local f = fs.open('/disk/next_chunk', 'r')
	next_chunk = tonumber(f.readAll())
	f.close()
end

if not fs.exists('/api') then
	fs.makeDir('/api')
end
if not fs.exists('/lib') then
	fs.makeDir('/lib')
end
if not fs.exists('/lib/status.lua') then
	fs.copy('/disk/lib/status.lua', '/lib/status.lua')
end
if not fs.exists('/lib/serialize.lua') then
	fs.copy('/disk/lib/serialize.lua', '/lib/serialize.lua')
end
if not fs.exists('/api/logf') then
	fs.copy('/disk/api/logf', '/api/logf')
end
if not fs.exists('/lib/state_machine.lua') then
	fs.copy('/disk/lib/state_machine.lua', '/lib/state_machine.lua')
end
if not fs.exists('/api/inventory') then
	fs.copy('/disk/api/inventory', '/api/inventory')
end
if not fs.exists('/api/turtle_utils') then
	fs.copy('/disk/api/turtle_utils', '/api/turtle_utils')
end
if not fs.exists('/mine3') then
	fs.copy('/disk/mine3', '/mine3')
end

startupFile = fs.open('/startup', 'w')
startupFile.write('shell.run(\'mine3\')')
startupFile.close()

ncFile = fs.open('/disk/next_chunk', 'w')
ncFile.write(tostring(next_chunk+1))
ncFile.close()
os.setComputerLabel('miner-'..tostring(next_chunk))
shell.run('mine3 8 68 '..tostring(next_chunk))